package com.alex.utils.text;

import java.util.regex.Pattern;

public abstract class TextUtils {
	
	private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\p{Z}+");

	private static final Pattern PUNCT_PATTERN = Pattern.compile("\\p{Punct}");
	
	public static boolean isEndOfSentence(String str) {
		return str.length() > 0 && isEndOfSentence(str.charAt(0));
	}
	
	public static boolean isEndOfSentence(char c) {
		return c == '.' || c == '!' || c == '?';
	}
	
	public static boolean isPunct(String token) {
		return PUNCT_PATTERN.matcher(token.substring(0, 1)).matches();
	}
	
	public static String makeSingleWhitespaces(String text) {
		return WHITESPACE_PATTERN.matcher(text).replaceAll(" ");
	}

	
}
